/**
 * Created by zcb on 15-7-11.
 */


define([
	'colorpicker',
	'layer',
	'../../Shop/module/STH_main.js',
	'jRange'
], function(colorpicker,layer,main,jRange){

	return {

	
	    //加入模块
	    blankAddM:function(con){
	    	
	    	var _this=this,
	    	    key=con.key,
	    	    order = con.order, 
	    	    blankValue=con.prop.blankValue,
	    	    blankColor=con.prop.blankColor,
	    	    
	    	    
	    	    newPanel=main.getPanel("blank"),
	            newEdit=main.getEdit("blank"); 
	            
		        //属性操作
		        $(newPanel).attr("order",order);
		        $(newPanel).attr("key",key);
		        $(newEdit).attr("key",key);
		        $(newEdit).css("display","none");
		        $(newPanel).find(".blank-box-p").height(blankValue);
		        $(newPanel).find(".blank-box-p").css('backgroundColor', blankColor );
		        $(newEdit).find('.STH_blank_edit .textcolor').css('backgroundColor', blankColor );
		        $(newEdit).find(".single-slider").val(blankValue);
		        $(newEdit).find(".tetxShow").html(blankValue+'像素');
		        $(newEdit).find(".tetxShow").css('left',blankValue*5);
				
		        
				
		        //延时顺序重定位
		        var edLength=$(".hb_box .panel-comp").length;
				if($(".hb_box .panel-comp").length<1 || order>parseInt($(".hb_box .panel-comp").eq(edLength-1).attr("order"))){
			        	$(".hb_box").append(newPanel);
			    }else if(order < parseInt($(".hb_box .panel-comp").eq(0).attr("order"))){
			       		$(".hb_box").prepend(newPanel);
			    }else{
			       	for(var r=0; r<edLength; r++){
			       		if(order > parseInt($(".hb_box .panel-comp").eq(r).attr("order")) && order < parseInt($(".hb_box .panel-comp").eq(r+1).attr("order"))){
			       				$(".hb_box .panel-comp").eq(r).after(newPanel);
			       				break;
			       		}	       			
			       	}
			    }
	            $(".edit-panel").append(newEdit);	           
	            _this.blankActive(newPanel,newEdit,key);	             
	    },
	
        //常规操作
        blankActive:function(thisPanel,thisEdit,key){        	
        	var _this=this;
        	
	     	if(typeof(g_data[key].prop.blankValue)=="undefined"){
		        	g_data[key].prop={
		        		"blankValue":10,
		        		"blankColor":"#DCDADA"
		        	}
		        	$(thisEdit).find('.STH_blank_edit .textcolor').css('backgroundColor', "#DCDADA");
	     	}
	     	
//	     	颜色选择 
			$(thisEdit).find('.STH_blank_edit .textcolor').ColorPicker({
                color: g_data[key].prop["blankColor"],
                onShow: function (colpkr) {
                    $(colpkr).fadeIn(500);
                    return false;
                },
                onHide: function (colpkr) {
                    $(colpkr).fadeOut(500);
                    return false;
                },
                onSubmit: function (hsb, hex, rgb,el) {
                    $(el).ColorPickerHide();
                    return false;
                },
                onChange: function (hsb, hex, rgb,el) { 
                	$(el).css('backgroundColor', '#' + hex);
                    g_data[key].prop["blankColor"] = '#' + hex;
                    $(thisPanel).find(".blank-box-p").css('backgroundColor', '#' + hex )
                    
                }
            });

			$(thisEdit).find('.single-slider').jRange({
				from: 1,
				to: 40,
				step: 1,
				format: '%s',
				width: 200,
				showLabels: true,
				showScale: false,
				onstatechange: function(){ 
					$(thisPanel).find(".blank-box-p").height($(thisEdit).find(".single-slider").val());
					g_data[key].prop.blankValue=$(thisEdit).find(".single-slider").val();					
					var w = $(thisEdit).find(".single-slider").val(),
				   		l = $(thisEdit).find('.selected-bar').css('width');
					$(thisEdit).find('.tetxShow').html(w+'像素').css('left',parseInt(l));
				}
			});
			
		    
		    //调用主模板JS
		    main.saveClick();
		    main.moduleActive();
	        main.dragEdit();
        }   

	}
});